<template>
    <admin-container :loading="loading" hidden-title id="app" style="margin: 0; padding: 0">
        <template v-if="isLogin">
            <router-view />

            <app-dialog/>

            <app-drawer/>

            <app-upload/>
        </template>

    </admin-container>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import AppDialog from '@/components/app-dialog/index.vue';
import AppUpload from '@/components/app-upload/index.vue';
import AppDrawer from '@/components/app-drawer/index.vue';
import AdminContainer from '@/components/admin-container.vue';
import { InitModule } from '@/store/initState';
import { AuthModule } from '@/store/auth';

@Component({
    name: 'App',
    components: { AdminContainer, AppDrawer, AppUpload, AppDialog }
})
export default class App extends Vue {
    get loading(): boolean {
        return InitModule.loading;
    }

    get isLogin(): boolean {
        return this.$route.name === 'login' || AuthModule.isLogin;
    }

    created() {
        window.onfocus = async () => {
            if (this.$route.name !== 'login') {
                try {
                    await AuthModule.getInfo();
                } catch (e) {
                    this.$message.error('登录超时,请重新登录');
                    await this.$router.push('/login');
                }
            }
        };
    }
}
</script>

<style lang="scss">
</style>
